﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MillerApp.DataContract.Common
{
    public class NumericHelper
    {
        public enum NumericFormat
        {
            Million,
            HundredMillion,
            Percent,
            Hundred,
        }

        /// <summary>
        /// 转换数字格式
        /// </summary>
        /// <param name="orgValue"></param>
        /// <param name="format"></param>
        /// <param name="isGroup"></param>
        /// <param name="decimals"></param>
        /// <returns></returns>
        public static string GetNumericFormatString(object orgValue, NumericFormat format, bool isGroup, int decimals)
        {
            if (orgValue == null)
            {
                return string.Empty;
            }
            decimal dValue = 0;
            if (decimal.TryParse(orgValue.ToString(), out dValue) == false)
            {
                return string.Empty;
            }
            string postCode = "";
            switch (format)
            {
                case NumericFormat.HundredMillion://8个零
                    dValue = dValue / 100000000;
                    postCode = "亿";
                    break;
                case NumericFormat.Million://6个零
                    dValue = dValue / 1000000;
                    postCode = "百万";
                    break;
                
                case NumericFormat.Percent://
                    dValue = dValue *100;
                    postCode = "%";
                    break;
                default:
                    break;
            }
            string result = String.Format("{0:N" + decimals.ToString() + "}", dValue);
            result += postCode;
            return result;
        }
    }
}
